package com.mocha.bass.test.mianzhu;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.hyzh.latte.NezhaApplication;
import com.hyzh.latte.util.JsonUtil;
import com.hyzh.latte.vehicle.dmo.entity.CameraPGEntity;
import com.hyzh.latte.vehicle.dmo.entity.PointPGEntity;
import com.hyzh.latte.vehicle.dmo.entity.PolePGEntity;
import com.hyzh.latte.vehicle.dmo.entity.PolePointPGEntity;
import com.hyzh.latte.vehicle.repository.CameraPGRepository;
import com.hyzh.latte.vehicle.repository.PointPGRepository;
import com.hyzh.latte.vehicle.repository.PolePGRepository;
import com.hyzh.latte.vehicle.repository.PolePointPGRepository;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.BufferedWriter;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;

/**
 * @author songkui
 * @since 2024/4/23 17:42
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = NezhaApplication.class)
@Slf4j
public class DataToJson {

    @Autowired
    private PointPGRepository pointPGRepository;
    @Autowired
    private PolePointPGRepository polePointPGRepository;
    @Autowired
    private CameraPGRepository cameraPGRepository;
    @Autowired
    private PolePGRepository polePGRepository;


    @Test
    public void doPole() throws IOException {
        List<CameraPGEntity> list = cameraPGRepository.list();

        String filePath = "D:/camera.json";

        // 使用BufferedWriter写入文件
        BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter(filePath));
        bufferedWriter.write(JSON.toJSONString(list, SerializerFeature.PrettyFormat));
        bufferedWriter.close();
        System.out.println("写入成功（使用BufferedWriter）");

    }


}
